home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
uw_1.exe
/
UW_TUT7.C
< prev
next >
Wrap
Text File
|
1992-11-02
|
17KB
|
444 lines
/****************************************************************************/
/* UW_TUT7.C */
/* */
/* NOTE: THIS FILE IS PUBLIC DOMAIN AND MAY BE MODIFIED AND USED AT WILL */
/* */
/* Now we add background printing, allowing us to print a single record */
/* or all of the records. We will add another drop down menu to do this. */
/* Since we are already calling a background function to display the real- */
/* time clock, we cannot set the idle function to print. However, we can */
/* simply let the current idle function, "disp_time", call "print_in_bkgrnd"*/
/* Using this simple method, we can perform many tasks in the background! */
/* Notice that we print to LPT1 and make no arrangements for DOS critical */
/* errors! We are trying to show the use of the library as opposed to */
/* ideal guidelines for application development and don't want to complicate*/
/* this mini-app. */
/* */
/* Dr. Boyd Gafford */
/* Kevin Huck */
/* EnQue Software */
/* 09/11/92 */
/****************************************************************************/
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#ifndef __TURBOC__
#include <sys\types.h>
#endif
#include <sys\stat.h>
#include <time.h>
#include <ctype.h>
#include "uw.h" /* include the necessary headers */
#define MAX_CUST 100
typedef struct cust
{
int status;
int cust_no;
char business[34];
char name[34];
char addr[34];
char city[34];
char state[4];
char zip[10];
char phone[16];
char fax[16];
char date[10];
char memo[34];
char unused[26]; /* round out to 256 bytes */
} CUST;
/*----------------------- global window variables --------------------------*/
WINDOW Desk_wn, Window1;
CUST Customers[MAX_CUST];
char Fname[33];
MENU Top_menu, *Top_mnp = &Top_menu;
MENU Files_menu, Edit_menu, Print_menu;
MENU *Drop_mnps[3];
PRINT Print;
/*-------------------------------- prototypes ------------------------------*/
int disp_time(void);
void disp_cust(CUST *cp, WINDOW *wnp);
int file_load(CUST *customers);
int file_save(CUST *customers);
int get_fname(char *fname);
void print_cust(CUST *cp, PRINT *p);
/*********/
/* ~main */
/* ********************************************************************/
/* Demonstrate data entry capability... */
/****************************************************************************/
int main()
{
int i, ret_val, cust = 0, end_flag = 0, print_stat = 0;
WINDOW *wnp;
CUST *cp;
uchar back_att = (LIGHTGRAY << 4) | BLACK,
bdr_att = (LIGHTGRAY << 4) | BLACK,
csr_att = (CYAN << 4) | YELLOW,
first_att = (LIGHTGRAY << 4) | RED;
wnp = &Window1; /* set local window pointer */
init_video(80, 25); /* init video for 80 x 25 screen */
init_clock(0x3333); /* init clock irq at 91 tics/sec */
wn_create(0, 0, V_cols-1, V_rows-1, NO_BDR, WN_NORMAL, &Desk_wn);
link_window(&Desk_wn);
/*------------------------ create the menu system ------------------------*/
Drop_mnps[0] = &Files_menu;
Drop_mnps[1] = &Edit_menu;
Drop_mnps[2] = &Print_menu;
menu_create(0, 0, V_cols - 1, 0, M_HORIZONTAL,
back_att, bdr_att, csr_att, first_att,
NO_BDR, WN_NORMAL, Top_mnp);
item_add( " Files ", 1, 3, &Top_menu );
item_add( " Edit ", 2, 3, &Top_menu );
item_add( " Print ", 8, 3, &Top_menu );
menu_create(0, 1, 14, 5, M_VERTICAL,
back_att, bdr_att, csr_att, first_att,
SGL_BDR, WN_NORMAL, Drop_mnps[0]);
item_add( " Load File", 4, 1, &Files_menu );
item_add( " Save File", 5, 1, &Files_menu );
item_add( " Quit ", 3, 3, &Files_menu );
menu_create(11, 1, 32, 4, M_VERTICAL,
back_att, bdr_att, csr_att, first_att,
SGL_BDR, WN_NORMAL, Drop_mnps[1]);
item_add( " Clear Current", 6, 7, &Edit_menu );
item_add( " Clear All ", 7, 7, &Edit_menu );
menu_create(22, 1, 43, 4, M_VERTICAL,
back_att, bdr_att, csr_att, first_att,
SGL_BDR, WN_NORMAL, Drop_mnps[2]);
item_add( " Print Current", 9, 7, &Print_menu );
item_add( " Print All ", 10, 7, &Print_menu );
set_idle_func(disp_time); /* set background clock function */
wn_create(5, 5, 75, 20, SLD_BDR, WN_POPUP, wnp);
wn_color(YELLOW, BLUE, wnp); /* change the window colors */
wn_bdr_color(WHITE, BLUE, wnp); /* change the border's colors */
link_window(wnp);
/*------------- initialize first customer as EnQue Software --------------*/
cp = &Customers[0];
strcpy(cp->business, "EnQue Software");
strcpy(cp->name, "Kevin Huck & Boyd Gafford");
strcpy(cp->addr, "Rt. 1 Box 116C");
strcpy(cp->city, "Pleasant Hill");
strcpy(cp->state, "MO");
strcpy(cp->zip, "64080");
strcpy(cp->phone, "(816)987-2515");
strcpy(cp->fax, "(816)987-2515");
strcpy(cp->date, "09/11/92");
strcpy(cp->memo, "BBS 816-358-8990");
/*------------------------ initialize the printer ------------------------*/
if( init_printer("LPT1", NULL, 2048L, 2048L, &Print) )
print_stat = 1;
menu_set(Top_mnp);
while(!end_flag)
{
cp = &Customers[cust];
mv_cs(1,1, wnp);
wn_printf(wnp, "Customer:%3d", cust+1);
wn_plst(CENTERED, 3, "Use cursor keypad to select customer", &Desk_wn);
disp_cust(cp, wnp);
wait_event();
switch(Event.key)
{
/*------------------------- process menus ----------------------------*/
case KEY_ALT_Q: /* quit program */
end_flag = 1;
break;
case KEY_ALT_F: case KEY_ALT_E: case KEY_ALT_P:
m_show();
if( Event.key == KEY_ALT_F )
ret_val = menu_system_ll(&Top_menu,&Drop_mnps[0],0,'F',M_EXIT_ON_ESC);
else if( Event.key == KEY_ALT_E )
ret_val = menu_system_ll(&Top_menu,&Drop_mnps[0],0,'E',M_EXIT_ON_ESC);
else
ret_val = menu_system_ll(&Top_menu,&Drop_mnps[0],0,'P',M_EXIT_ON_ESC);
switch( ret_val )
{
case 3: /* quit program */
end_flag = 1;
break;
case 4: /* load file */
file_load(Customers);
break;
case 5: /* save file */
file_save(Customers);
break;
case 6: /* clear one */
setmem(cp, sizeof(CUST), 0);
break;
case 7: /* clear all */
setmem(Customers, sizeof(Customers), 0);
break;
case 9: /* print one */
if( print_stat )
print_cust(cp, &Print);
break;
case 10: /* print all */
if( print_stat )
for( i = 0; i < MAX_CUST; i++ )
if( strlen(Customers[i].name) ) /* not empty? */
print_cust(&Customers[i], &Print);
break;
}
break;
/*---------------------- process cursor keys -------------------------*/
case KEY_HOME:
cust = 0;
break;
case KE